#pragma once

#include "Communal.h"

// Single-level array
template <int BITS>
class TCMalloc_PageMap
{
private:
	static const int LENGTH = 1 << BITS;
	void** _array;

public:
	TCMalloc_PageMap()
	{
		size_t size = sizeof(void*) * LENGTH;
		size_t alignsize = SizeClass::RoundUp(size);
		_array = (void**)SystemAlloc(alignsize >> PAGE_SHIFT);
		memset(_array, 0, sizeof(void*) << BITS);
	}

	void* get(PAGE_ID k) const 
	{
		if ((k >> BITS) > 0)  return nullptr;
		return _array[k];
	}

	void set(PAGE_ID k, void* v)
	{
		_array[k] = v;
	}
};